<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/public/head::head(~{::title},~{},~{})">
    <title>管理员登录-饮食分析系统</title>
</head>
<body class="login-bg">
<style>
    .login-bg {
        /*background: url(../images/bg.png) no-repeat center;*/
        background-attachment: fixed;
        background-repeat:no-repeat;
        background: url("/common/images/bg1.jpg") no-repeat ;
        background-size: cover;
        overflow: hidden;
    }
</style>
<div class="login">
    <div class="message">饮食分析系统</div>
    <div id="darkbannerwrap"></div>
    <form method="post" class="layui-form">
        <input name="mobile" placeholder="手机号" type="text" lay-verify="required|mobile" class="layui-input">
        <hr class="hr15">
        <input name="password" lay-verify="required|password" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <select name="type" class="layui-select" th:placeholder="请选择角色">
            <option value="3">系统管理员</option>
<!--            <option value="2">回收员</option>-->
<!--            <option value="1">代收员</option>-->
<!--            <option value="0">普通会员</option>-->
        </select>
        <hr class="hr15">
        <input name="verifyCode" class="layui-input" placeholder="验证码" lay-verify="required|verify_code" type="text">
        <hr class="hr15">
        <img id="verify" onclick="refreshVerify()" th:src="@{/common/verifyCode/getVerifyCode}">
        <button onclick="refreshVerify('verify')" type="button" class="layui-btn">刷新</button>
        <hr class="hr15">

        <input class="loginin" value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">

        <hr class="hr20">
        <a style="margin-left:60%" href="/user/registPage">还没账号？点击注册</a>
    </form>
</div>

<script type="text/javascript">
    layui.use(['form', 'admin'], function () {
        var form = layui.form
            , admin = layui.admin;

        form.on('submit(login)', function (data) {
            console.log(data.field);
            var url="/admin/checkLogin";
            if(data.field.type==3){
                console.log("this is admin login...");
            }else{
                url="/user/checkLogin";
            }
            $.post(url, data.field, function (res) {
                console.log(res);
                if (!res.success) {
                    layer.msg(res.msg, {icon: 2, time: 1500});
                    return false;
                }
                location.href = '/admin/index';
            });
            return false;
        });

        //自定义表单验证
        form.verify({
            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            password: [
                /^[\S]{6,16}$/
                , '密码必须6到16位，且不能出现空格'
            ],
            verify_code: [
                /^.{4}$/
                , '验证码为4位字符！'
            ]
        });
    });
</script>
<!-- 底部结束 -->
</body>
</html>